//
//  SuggestViewController.m
//  UniversalApp
//
//  Created by 奇林刘 on 2018/11/27.
//  Copyright © 2018 voidcat. All rights reserved.
//

#import "SuggestViewController.h"

@interface SuggestViewController ()

@property (nonatomic, strong) UITextView *suggestTextView;
@property (nonatomic, strong) UIButton *suggestButton;

@end

@implementation SuggestViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = CViewBgColor;
    self.title = @"投诉建议";
    [self setUpUI];
}

- (void)setUpUI {
    self.suggestTextView = [[UITextView alloc] init];
    self.suggestButton = [[UIButton alloc] init];
    [self.view addSubview:self.suggestTextView];
    [self.view addSubview:self.suggestButton];
    [self layoutUI];
    [self configUI];
}

- (void)layoutUI {
    [self.suggestTextView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.mas_top).offset(20);
        make.width.equalTo(@(KScreenWidth - 40));
        make.height.equalTo(@(KScreenHeight * 0.4));
        make.centerX.equalTo(self.view);
    }];
    
    [self.suggestButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.suggestTextView.mas_bottom).offset(20);
        make.width.equalTo(self.suggestTextView);
        make.height.equalTo(@(50));
        make.centerX.equalTo(self.view);
    }];
}

- (void)configUI {
    ViewBorderRadius(self.suggestTextView, 10, 1, CLineColor);
    self.suggestTextView.zw_placeHolder = @"请输入您的意见...";
    ViewBorderRadius(self.suggestButton, 10, 1, CLineColor);
    [self.suggestButton addTarget:self action:@selector(onSuggestButtonTap) forControlEvents:UIControlEventTouchUpInside];
    [self.suggestButton setBackgroundColor:UIColorWhite];
    [self.suggestButton setTitle:@"提交建议" forState:UIControlStateNormal];
    [self.suggestButton setTitleColor:UIColorBlack forState:UIControlStateNormal];
}

- (void)onSuggestButtonTap {
    NSString *url = [[CYURLUtils sharedCYURLUtils] makeURLWithC:@"user_api" A:@"feedback"];
    
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"uid"] = [UserManager sharedUserManager].curUserInfo.id;
    param[@"token"] = [UserManager sharedUserManager].token;
    param[@"content"] = self.suggestTextView.text;
    
    [CYNET POSTv2:url parameters:param responseCache:^(id responseObject) {
        
    } success:^(id responseObject) {
        [MBProgressHUD showTopTipMessage:ASLocalizedString(@"发布成功")];
        [self.navigationController popViewControllerAnimated:YES];
    } failure:^(NSString *error) {
        [MBProgressHUD showTopTipMessage:error];
    } hasCache:NO];
    
}




@end
